#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

bool judge(char a)
{
    if ((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z'))
        return true;
    else
        return false;
}

int main()
{
    int t;
    string a;
    while (cin >> t)
    {
        getchar();
        while (t-- && getline(cin, a))
        {
            for (int i = 0; i < a.size(); i++)
            {
                if (judge(a[i]))
                {
                    if (i == 0)
                    {
                        if (a[i] >= 'a' && a[i] <= 'z')
                            a[i] = a[i] - 'a' + 'A';
                        cout << a[i];
                    }
                    else if (!judge(a[i - 1]))
                    {
                        if (a[i] >= 'a' && a[i] <= 'z')
                            a[i] = a[i] - 'a' + 'A';
                        cout << a[i];
                    }
                }
            }
            cout << endl;
        }
    }
    return 0;
}